import { _decorator, Component, EditBox, Label, Layout, Node, ScrollView, Slider, Sprite, Toggle, Vec2, Vec3 } from 'cc';
import { UIManager } from '../UIManager';
import { LanauageManager } from '../LanauageManager';
import { GameData } from '../GameData';
import { HttpClient } from '../net/HttpClient';
import { EventManager } from '../EventManager';
import { AudioMgr } from '../AudioMgr';
import { Util } from '../Util';
const { ccclass, property } = _decorator;

@ccclass('popupMyInfo')
export class popupMyInfo extends Component {

    @property(Sprite)
    avatar:Sprite = null;

    @property(Label)
    nameLab:Label = null;

    @property(Label)
    idLab:Label = null;

    @property(Label)
    coinLab:Label = null;

    @property(EditBox)
    signEdit:EditBox = null;

    @property(Label)
    dayLab:Label = null;

    @property([Label])
    shopNumLabs :Label[] = [];

    selectId:number = 1;

    protected start(): void {
        EventManager.eventTarget.on(EventManager.REFRESH_GAME, this.refresh, this);
    }
    
    onEnable() {
        this.refresh();
    }

    refresh(){
        if (!this.node.active){
            return;
        }

        Util.loadRemoteUrl(GameData.getIns().userData.avatar, this.avatar);

        this.nameLab.string = GameData.getIns().userData.nickname;

        this.idLab.string = "ID: " + GameData.getIns().userData.id;

        this.coinLab.string = GameData.getIns().userData.coin + "";

        this.signEdit.string = GameData.getIns().userData.introduce==null?"":GameData.getIns().userData.introduce;

        this.dayLab.string = GameData.getIns().userData.leftDay + "";

        let starNums:number[] = [GameData.getIns().userData.onestarNum, GameData.getIns().userData.twostarNum, GameData.getIns().userData.threestarNum, GameData.getIns().userData.fourstarNum, GameData.getIns().userData.fivestarNum]
    
        for (let index = 0; index < this.shopNumLabs.length; index++) {
            let element = this.shopNumLabs[index];
            element.string = starNums[index] + "";
        }
    }

    onClickHandler(event:Event, str:string){
        if (str == "newBtn"){
            UIManager.open(UIManager.uiNamePath.popupShopNew)
        }
        else if (str == "manger"){
            UIManager.open(UIManager.uiNamePath.popupShopMang, {type: 1})
        }
        else if (str == "upShow"){
            UIManager.open(UIManager.uiNamePath.popupShopMang, {type: 2})
        }
        else if (str == "share"){
            Util.shareGame();
        }
        else if (str == "chaneName"){
            UIManager.open(UIManager.uiNamePath.popupComonTip, {statu: 1})
        }
        else if (str == "chaneSign"){
            UIManager.open(UIManager.uiNamePath.popupComonTip, {statu: 0, sign:this.signEdit.string, type:0})
        }
        else if (str == "AIPay"){
            UIManager.open(UIManager.uiNamePath.popupComonTip, {statu: 2})
        }
    }
}

